﻿package com.valorin.itemstack;

import java.util.ArrayList;
import java.util.List;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

public class ItemCreator {
  private ItemStack itemstack;
  
  public ItemStack get() {
	return itemstack;
  }
  /*
   * material必填
   * displayname,lore,mark选填 但要同时存在
   * 用于背包物品
   */
  public ItemCreator(
		  Material material,
		  String displayname,
		  List<String> lore,
		  String mark)
  {
	ItemStack itemstack = new ItemStack(material);
	ItemMeta im;
	if (displayname != null && mark != null) {
	  im = itemstack.getItemMeta();
	  im.setDisplayName(displayname);
	  itemstack.setItemMeta(im);
	}
	if (lore != null && mark != null) {
	  im = itemstack.getItemMeta();
	  List<String> list = new ArrayList<String>();
	  list.add(mark);
	  list.addAll(lore);
	  im.setLore(list);
	  itemstack.setItemMeta(im);
	}
	this.itemstack = itemstack;
  }
  /*
   * material必填
   * displayname,lore选填，无其他特殊要求
   * 用于GUI物品
   */
  public ItemCreator(
		  Material material,
		  String displayname,
		  List<String> lore,int s)
  {
	ItemStack itemstack = new ItemStack(material,1,(short)s);
	ItemMeta im = itemstack.getItemMeta();;
	if (im != null) {
	  if (displayname != null) {
	    im.setDisplayName(displayname);
	    itemstack.setItemMeta(im);
	  }
	  if (lore != null) {
	    im.setLore(lore);
	    itemstack.setItemMeta(im);
	  }
	}
	this.itemstack = itemstack;
  }
}
